<?php
//view.php

//** Each page that is "stand alone" must have this variable.
$authorizedPage = true; 
require('config.php');
require('recipie.php');


$rid = 0;
if(isset($_GET['rid'])) $rid = $_GET['rid'];
	
$recipie = new Recipie($rid);
if(!$recipie->fillVariables()) generateErrorPage(101);

function generateList($listArray, $imglistArray){
	echo '<div class="thumbnails yoxview">';
	echo "<ol>";
	foreach($listArray as $key=>$value){
		if(strlen($value) < 1) continue;
		echo "<li>";
		echo $value;
		
		if(checkValidImage($imglistArray[$key]) == 1){
			echo "<br />";
			echo '<a href="images/user/' . $imglistArray[$key] . '">';
			echo '<img src="images/user/normalthumb/thumb' . $imglistArray[$key] . '" alt="Food" />';
			echo '</a>';
		}
		
		echo "</li>";
	}
	echo "</ol>";
	echo '</div>';
}

function generateStepList($listArray, $imglistArray, $timeArray){
	echo '<div class="thumbnails yoxview">';
	echo "<ol>";
	foreach($listArray as $key=>$value){
		if(strlen($value) < 1) continue;
		echo "<li class=\"stepP\" id=\"{$key}\">";
		echo $value;
		echo "<br />";
		echo "Estimated time: " . (isset($timeArray[$key]) ? $timeArray[$key] : 1 ) . " minutes.";
		echo '<input type="hidden" name="time[]" class="time" value="'.(isset($timeArray[$key]) ? $timeArray[$key] : 1).'" />';
		
		if(checkValidImage($imglistArray[$key]) == 1){
			echo "<br />";
			echo '<a href="images/user/' . $imglistArray[$key] . '">';
			echo '<img src="images/user/normalthumb/thumb' . $imglistArray[$key] . '" alt="Food" />';
			echo '</a>';
		}
		
		echo "</li>";
	}
	echo "</ol>";
	echo '</div>';
}

//**checkValidImage
//@img					The image string to check
//return				returns 1 if image, -1 if error, 0 if no image
function checkValidImage($img){
	if($img == "None") return 0;
	if(strpos($img, "Error")) return -1;
	return 1;
}

?>

<!--Shell Start-->
<!DOCTYPE HTML>
<html xmlns:fb="http://ogp.me/ns/fb#">

<head>
<title><?php echo $recipie->getRName(); ?></title>
<link rel="stylesheet" type="text/css" href="libraries/style.css" />
<link rel="stylesheet" type="text/css" href="style/create.css" />
<script type="text/javascript" src="libraries/jq.js"></script>
<script type="text/javascript" src="yoxview/yoxview-init.js"></script>
<script type="text/javascript" src="libraries/collapse.js"></script>
<script type="text/javascript" src="libraries/search.js"></script>
<script type="text/javascript" src="libraries/jquery.sticky.js"></script>
<script type="text/javascript" src="libraries/kinetic-v4.0.5.min.js"></script>
<script type="text/javascript" src="libraries/timeline.js"></script>
</head>

<body>

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=<?php echo $developmentId; ?>";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

	
	<div id="contain">

		<div id="primitiveHead">
			<img id="logo" alt="Friendly Cooks" src="images/logo.png" />
			<div id="logoContain"></div>
			<?php require('facebook/f_authenticate.php'); ?>
			<form method="get" action="searchresults.php">
				<input id="search" name="search" type="text" value="search..." />
				<input id="go" type="submit" name="searchGO" value="Go!" />
			</form>
			<a href="create.php"><img id="create" src="images/createrecipe.png" /></a>
		</div>
	

	
		<div id="primitiveBody">
		
		<?php
			/*
				User of created page needs option to edit
				User of create page needs option to delete
				Use Recipie Class to provide edit and update features
				Use a modified version of create, echo out the forms, happy days
			*/
		?>
		
			<h1>
				<?php echo $recipie->getRName(); ?>
				<span class="v_by">
					by <?php echo $recipie->getRFacebookName(); ?>
				</span>
			</h1>
			
			<div class="primitiveContent">
			
				<div class="v_fb_like">
					<div>
						<?php require('facebook/f_like.php'); ?>
					</div>
				</div>

				<div class="v_description">
						<?php if(checkValidImage($recipie->getRImgMain())){
								echo '<div class="thumbnails yoxview">';
								echo '<a href="images/user/'.$recipie->getRImgMain().'">';
								echo '<img src="images/user/largethumb/thumb'. $recipie->getRImgMain().'" alt="Food" align="left"/>';
								echo '</a>';
								echo '</div>';
						}
						?>
				</div>
				
				<div>				
					<p>
						<?php
								echo $recipie->getRDescription(); //Description
							?>
					</p>
						
				</div>
				
				<div id="timeLineWrap">
				<div id="timeLine"></div>
				
				</div>
				
				<div class="timeLineSpace">
					
				</div>
				
				<div class="timelineText">
				
				<div style="text-align: center; margin-left: auto; margin-right: auto; width: 1000px;">
					Ticker Position: <span class="timelineCurrentPosition"></span> 
					<span class="timelinePLAY"><img class="clickable" src="images/Play-Hot-icon.png"/></span>
					<span class="timelinePAUSE"><img class="clickable" src="images/Pause-Normal-Red-icon.png"/></span>
				</div>
				
				</div>
				
				<input type="hidden" id="totalTime" value="<?php echo $recipie->getRTotalTimes()*60 + 17 + (count($recipie->getRTimes()) - 1) * 20;?>" />
				
				<h5 class="toggle">Materials</h5>
					<div class="toToggle">
						<?php generateList($recipie->getRMaterials(),  $recipie->getRImgMate()); ?>
					</div>
				<h5 class="toggle">Ingredients</h5>
					<div class="toToggle">
						<?php generateList($recipie->getRIngredients(), $recipie->getRImgIngr()); ?>
					</div>
				<h5 class="toggle">Steps</h5>
					<div class="toToggle">
						<?php generateStepList($recipie->getRSteps(),$recipie->getRImgStep(), $recipie->getRTimes()); ?>
						<script type="text/javascript">
						$('document').ready(function(){
						generateSteps();
						$(".yoxview").yoxview();
						});
						</script>
					</div>
				<h5 class="toggle">Comments</h5>
					<div class="toToggle">
						<fb:comments href="<?php echo get_full_url() ?>" num_posts="4" width="980"></fb:comments>
					</div>

			</div>
			
			
			<div id="primitiveFoot">
				<img id="minilogo" alt="Friendly Cooks" src="images/logo.png" />
				
				<span id="footLinks">
					<a href="index.php">Home</a> |
					<a href="create.php">Create</a> |
					<a href="view.php">View</a> |
					<a href="search.php">Search</a> |
					<a href="privacy.php">Privacy</a> |
					<a href="contact.php">Contact</a> |
					<a href="account.php?id=<?php echo ($user ? $user_profile['id'] : -1);  ?>" id="accountFoot">My Account</a>

					
					<span>&copy; 2012 Friendly Cooks</span>
				</span>
			</div>
			
		</div>

	</div>


</body>
</html>

<?php
mysql_close();

?>